package com.koron.standard.instructionStock.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.koron.bean.base.Response;
import com.koron.standard.bean.query.PageQuery;
import com.koron.standard.instructionStock.bean.po.Instruction;
import com.koron.standard.instructionStock.bean.query.InstructionQuery;
import com.koron.standard.instructionStock.bean.vo.InstructionVO;
import com.koron.standard.instructionStock.service.InstructionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jzp
 * @since 2021/9/6
 */
@Api(tags = "作业指导书库接口")
@RestController
@RequestMapping("instruction")
public class InstructionController {

    @Autowired
    private InstructionService instructionService;

    @GetMapping
    @ApiOperation(value = "根据id查询")
    public Response<InstructionVO> select(@RequestParam String id) {
        return Response.ok(instructionService.getRealById(id));
    }

    @GetMapping("page")
    @ApiOperation(value = "分页查询")
    public Response<Page<InstructionVO>> page(PageQuery<InstructionVO> pageQuery, InstructionQuery query) {
        Page<InstructionVO> page = instructionService.page(pageQuery, query);
        return Response.succ(page, page.getTotal());
    }

    @PostMapping
    @ApiOperation(value = "保存")
    public Response uploadPost(@RequestBody Instruction instruction) {
        instructionService.save(instruction);
        return Response.ok(instruction.getId());
    }

    @PutMapping
    @ApiOperation(value = "更新")
    public Response uploadPut(@RequestBody Instruction instruction) {
        instructionService.updateById(instruction);
        return Response.ok();
    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    public Response delete(@RequestParam("ids") List<String> ids) {
        instructionService.removeByIds(ids);
        return Response.ok();
    }

    @ApiOperation(value = "设置为公共标准")
    @PutMapping("updateToPublic")
    public Response updateToPublic(@RequestParam("ids") List<String> ids) {
        instructionService.updateToPublic(ids);
        return Response.ok();
    }

}
